package com.qnvip.sbd.mybatis.util;

import java.util.ArrayList;
import java.util.List;

public class SelectMap {

	private String equals = "=";
	
	private String targetColumn;
	private String table;
	private String join;
	private String orderBy;
	private String limit;
	private String having;
	private String gorupBy;
	private List<Field> where = new ArrayList<Field>();
	private List<String> joins = new ArrayList<>();
	
	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public String getTargetColumn() {
		return targetColumn;
	}

	public void setTargetColumn(String targetColumn) {
		this.targetColumn = targetColumn;
	}

	public String getJoin() {
		return join;
	}

	public void setJoin(String join) {
		this.join = join;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getLimit() {
		return limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public String getHaving() {
		return having;
	}

	public void setHaving(String having) {
		this.having = having;
	}

	public String getGorupBy() {
		return gorupBy;
	}

	public void setGorupBy(String gorupBy) {
		this.gorupBy = gorupBy;
	}

	/**
	 * @param name
	 * @param value
	 */
	public SelectMap addWhere(String name, String value) {
		where.add(new Field(name, value, equals));
		return this;
	}

	/**
	 * @param name
	 * @param value
	 */
	public SelectMap addWhere(String name, int value) {
		where.add(new Field(name, String.valueOf(value), equals));
		return this;
	}
	
	/**
	 * @param name
	 * @param value
	 */
	public SelectMap addWhere(String name, Long value) {
		where.add(new Field(name, String.valueOf(value), equals));
		return this;
	}

	/**
	 * @param name
	 * @param value
	 * @param operator
	 */
	public SelectMap addWhere(String name, String value, String operator) {
		where.add(new Field(name, value, operator));
		return this;
	}

	/**
	 * @param name
	 * @param value
	 * @param operator
	 */
	public SelectMap addWhere(String name, int value, String operator) {
		where.add(new Field(name, String.valueOf(value), operator));
		return this;
	}
	
	/**
	 * @param name
	 * @param value
	 * @param operator
	 */
	public SelectMap addWhere(String name, Long value, String operator) {
		where.add(new Field(name, String.valueOf(value), operator));
		return this;
	}

	/**
	 * 
	 * @param name
	 * @param value
	 * @param column  true=$$ false=##
	 */
	public SelectMap addWhere(String name, String value, boolean column) {
		where.add(new Field(name, value, equals, column));
		return this;
	}

	/**
	 * 
	 * @param name
	 * @param vlaue
	 * @param operator
	 * @param column
	 */
	public SelectMap addWhere(String name, String value, String operator, boolean column) {
		where.add(new Field(name, value, operator, column));
		return this;
	}

	public List<Field> getWhere() {
		return where;
	}

	public void setWhere(List<Field> where) {
		this.where = where;
	}
	
	public SelectMap addJoin(String joinSql) {
		joins.add(joinSql);
		return this;
	}

	public List<String> getJoins() {
		return joins;
	}
}
